﻿<html>

<head>
    <title>品质检测-精工云MES系统移动端</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link href="/JG/Content/jquery/weui/style/weui.min.css" rel="stylesheet" />
    <link href="/JG/Content/jquery/jquery-weui/css/jquery-weui.min.css" rel="stylesheet" />
    <link href="/JG/Content/css/bootstrap.min.css" rel="stylesheet" />
    <link href="/JG/Content/css/Global.css" rel="stylesheet" />
    <link rel="stylesheet" href="/JG/Content/css/QualityInspection.css?v=1">
    <script src="/JG/Content/LocalConfigs.js"></script>
    <script src="/JG/Content/LocalUserInfo.js"></script>
</head>

<body ontouchstart>
    <!--title部分-->
    <header class="header">
        <div class="empty">
            <span id="stations"></span>
        </div>
        <div class="item header_title">
            <a href="javascript:;">品质检测</a>
        </div>
        <div class="item item2">
            <div class="set">
                <!--<span class="glyphicon glyphicon-cog" style="font-size: 50px;color:#FFFFFF"></span>-->
                <span><img style="width:50px" src="/JG/Content/images/early.png" alt=""></span>
            </div>
            <div class="user_img" onclick="javascript:location.href='/JG/Home/Index.html'">
                <span class="back"><img src="/JG/Content/images/return.png" alt=""></span>
            </div>
            <div class="clean"></div>
        </div>
    </header>

    <div id="MainPage" class="MainPage">
        <div class="input-group" style="text-align:center;font-size:18px;">
            <label class="input-group-addon" for="BarCode">SN码</label>
            <input type="text" class="form-control" maxlength="50" v-model="BarCode" placeholder="扫描或输入SN码回车" id="BarCode"
                :disabled="IsDisable" />
        </div>
        <div id="tab2" class="weui-tab__bd-item">
            <div class="left">
                <ul class="list-group">
                    <!-- <li class="list-group-item" v-if="CurrProcessName">当前工序&nbsp;&nbsp;{{CurrProcessName}}</li> -->
                    <li class="list-group-item">当前SN码&nbsp;&nbsp;{{CurrBarCode}}
                    </li>
                    <li class="list-group-item">
                        任务单号&nbsp;&nbsp;{{FormData.TaskCode}}
                    </li>
                    <!-- <li class="list-group-item">
                        产品码&nbsp; &nbsp;{{FormData.InvBarCode}}
                    </li> -->
                    <li class="list-group-item">
                        产品编码&nbsp; &nbsp;{{FormData.InvCode}}
                    </li>
                    <li class="list-group-item">
                        产品名称&nbsp; &nbsp;{{FormData.InvName}}
                    </li>
                    <li class="list-group-item">
                        产品型号&nbsp; &nbsp;{{FormData.InvStd}}
                    </li>
                    <li class="list-group-item">
                        任务数量&nbsp;&nbsp;{{FormData.TaskQty}}
                    </li>
                    <li class="list-group-item">
                        已扫数量&nbsp;&nbsp;{{ScanCodeNum}}
                    </li>
                </ul>
            </div>

            <div class="right  panel panel-default">
                <ul class="nav nav-tabs">
                    <li class="active">
                        <a href="#OperateRecord" data-toggle="tab">操作记录</a>
                    </li>
                    <li>
                        <a href="#Swiper" data-toggle="tab">操作指导</a>
                    </li>
                </ul>
                <div class="tab-content tabs">
                    <div class="tab-pane fade in active" id="OperateRecord">
                        <ul style="height:100%;overflow-y:auto;">
                            <li style="font-size: 1.2em" v-for="(item,index) in OperateRecord" :style="{'color':item.Status?'blue':'red'}">
                                {{item.Content}}
                            </li>
                        </ul>
                    </div>
                    <div class="tab-pane fade" id="Swiper">
                        <div class="swiper-container">
                            <div class="swiper-wrapper" id="Top_Swiper">
                            </div>
                            <div class="swiper-pagination"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row" style="margin-left:5px">
            <button class="btn1 btn btn-success" type="button" v-if="DefectiveItemData.length>0" style="margin-top:10px;margin-left:15px;height:75px;width:115px"
                v-on:click="PassSubmitData()" :disabled="IsSubmit">
                PASS
            </button>
            <!--文字限长6个字符串-->
            <button type="button" v-for="(item,index) in DefectiveItemData" class="btn2 btn btn-warning" role="button"
                style="margin-top:10px;margin-left:15px;height:75px;width:115px" v-on:click="SubmitDetectionItem(item)">
                {{item.ItemName}}
                <span>
                    <img src="/JG/Content/images/yixuan.png" style="display: none" :id="item.ID" />
                </span>
            </button>
            <button class="btn3 btn btn-danger" type="button" v-if="DefectiveItemData.length>0" style="margin-top:10px;margin-left:15px;height:75px;width:115px"
                v-on:click="SubmitData()" :disabled="IsSubmit">
                提 交
            </button>
        </div>

        <div class="panel panel-default">
            <div class="panel-heading panel-heading1">
                过站记录
            </div>
            <table class="table">
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>SN码</th>
                        <th>产品</th>
                        <th>过站时间</th>
                        <th>操作人</th>
                        <th>过站状态</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item,index) in StationRecord">
                        <td>{{index+1}}</td>
                        <td>{{item.BarCode}}</td>
                        <td>{{item.InvName}}\{{item.InvStd}}</td>
                        <td>{{item.StationTime}}</td>
                        <td>{{item.Operator}}</td>
                        <td><span :style="item.PassState=='Pass'?'color:green':'color:red'">{{item.PassState}}</span></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    <script src="/JG/Content/jquery/jquery-3.2.1.min.js"></script>
    <script src="/JG/Content/jquery/jquery-weui/js/jquery-weui.min.js"></script>
    <script src="/JG/Content/bootstrap.min.js"></script>
    <script src="/JG/Content/Utils.js?v=1"></script>
    <script src="/JG//Content//AudioUtils.js"></script>
    <script src="/JG/Content/Common.js"></script>
    <script src="/JG//Content/Station.js"></script>
    <script src="/JG/Content/jquery/jquery-weui/js/swiper.min.js"></script>
    <script src="/JG/Content/jquery/fastclick.js"></script>
    <script>
        $(function () {
            FastClick.attach(document.body);
            Station.Init(".header");
            var stations = LocalUserInfo.GetUserInfo();
            $("#stations").html(stations.ProductionLineName + " - " + stations.StationName);
        });
    </script>
    <script src="/JG/Content/vue-v2.34.js"></script>
    <script type="text/javascript">
        var vmPage = new Vue({
            el: "#MainPage",
            data: {
                CurrProcessType: "GXLX005", //当前工序类型
                CurrProcessCode: "",  //当前工序编码
                CurrProcessName: "",  //当前工序名称 
                ScanCodeNum: 0,        //扫码数量
                CurrBarCode: "",       //当前条码
                BarCode: "",
                IsDisable: false,
                IsSubmit: true,//是否Pass
                FormData: {
                    ScheduleID: "", //排产单ID
                    TaskCode: "",   //任务号
                    TaskQty: "", //任务数量
                    InvCode: "",
                    InvName: "",
                    InvStd: "",
                    InvBarCode: "",
                    InvProcessType: "",
                    SOPImagePaths: [],
                },
                DefectiveItemData: [],
                SelectItemData: [],
                StationRecord: [],
                OperateRecord: []
            },
            mounted: function () {
                var currSelf = this;
                $("#BarCode").bind("keypress", currSelf.SearchBarCode);
                $("#BarCode").focus();
                Utils.AutoBarCodeFocus();
                
                $.showLoading();
                $.ajax({
                    type: "post",
                    url: LocalConfig.SrvPath + "/jgmes/commonAction!getCurrentProductByCxCp.action",
                    data: { userCode: LocalUserInfo.GetUserInfo().UserCode, mac: LocalUserInfo.GetUserInfo().Mac, cxCode: LocalUserInfo.GetUserInfo().ProductionLineCode },
                    dataType: "json",
                    success: function (ret) {
                        var retData = ReturnData(ret);
                        if (retData.IsSuccess && retData.Data) {
                            currSelf.SetBasetData(retData);
                        }
                        //不良项
                        if (currSelf.FormData.InvCode) {
                            $.ajax({
                                type: "post",
                                async: false,
                                cache: true,
                                url: LocalConfig.SrvPath + "/jgmes/commonAction!getGXBLXMList.action",
                                data: { userCode: LocalUserInfo.GetUserInfo().UserCode, mac: LocalUserInfo.GetUserInfo().Mac, cpCode: currSelf.FormData.InvCode },
                                dataType: "json",
                                success: function (ret) {
                                    var retData = ReturnData(ret);
                                    if (retData.IsSuccess) {
                                        if (retData.Data) {
                                            for (var i in retData.Data) {
                                                var element = retData.Data[i];
                                                currSelf.DefectiveItemData.push({ ID: element.GXBLX_BLXBH, ItemName: element.GXBLX_BLXMC });
                                            }
                                        } else {
                                            var content = "未找到产品相关不良项目";
                                            currSelf.SetOperateRecord(content, false);
                                            $.toptip(content, "warning");
                                        }
                                    }
                                },
                                error: function (xhr, status, err) {
                                     console.error(status);
                                    $.alert("请求失败");
                                }
                            });
                        }
                    }, error: function (xhr, status, errorThrown) {
                        $.alert("请求失败");
                    }, complete() {
                        $.hideLoading();
                    }
                });
            },
            methods: {
                SetOperateRecord: function (content, status) {
                    var currSelf = this;
                    var content = (new Date().Format("hh:mm:sss")) + ' ' + content;
                    currSelf.OperateRecord.splice(0, 0, { Content: content, Status: status });
                },
                SetBasetData: function (retData) {
                    var currSelf = this;
                    currSelf.FormData.ScheduleID = retData.Data.JGMES_PLAN_SCRW_ID;
                    currSelf.FormData.TaskCode = retData.Data.SCRW_RWDH;
                    currSelf.FormData.InvCode = retData.Data.SCRW_CPBH;
                    currSelf.FormData.InvName = retData.Data.SCRW_NAME;
                    currSelf.FormData.InvStd = retData.Data.SCRW_CPGG;
                    currSelf.FormData.LineCode = retData.Data.SCRW_CXBM;
                    currSelf.FormData.LineCode = retData.Data.SCRW_CXMC;
                    currSelf.FormData.TaskQty = retData.Data.SCRW_PCSL;
                    //获取当前用户当前产品的工序
                    var data = GetCurrentProcess(currSelf.FormData.InvCode);
                    //获取当前已扫码数量
                    var NumData = GetCountScan();
                    console.log(NumData);
                    if (NumData.IsSuccess && NumData.Data) {
                        currSelf.ScanCodeNum = NumData.Data;
                    }

                    if (data.IsSuccess && data.Data) {
                        currSelf.FormData.InvProcessType = data.Data.GXGL_GXLX_NAME;
                        currSelf.CurrProcessCode = data.Data.GXGL_GXNUM;
                        currSelf.CurrProcessName = data.Data.GXGL_GXNAME;
                        if (data.Data.GXGL_SOP && data.Data.GXGL_SOP.length > 0) {
                            var htmlAppend = "";
                            var imgSOPs = JSON.parse(data.Data.GXGL_SOP);
                            for (var index in imgSOPs) {
                                var item = imgSOPs[index];
                                htmlAppend += "<div class='swiper-slide'><img style='width:100%;height:100%' src='" + LocalConfig.SrvPath + item.path + "'/></div>";
                            }
                            $("#Top_Swiper").append(htmlAppend);
                            if (imgSOPs && imgSOPs.length > 1) {
                                $(".swiper-container").swiper({
                                    loop: true,
                                    autoplay: 3000
                                });
                            }
                        }
                    }
                },
                SearchBarCode: function (event) {
                    console.log(event);
                    var currSelf = this;
                    if (event.which == 13) {
                        var barCode = currSelf.BarCode;
                        currSelf.BarCode = "";
                        var showMsg;
                        currSelf.IsDisable = true;
                        if (currSelf.IsSubmit == false) //继续扫码自动PASS
                            currSelf.PassSubmitData(currSelf.FormData.InvBarCode, false);

                        if (!currSelf.FormData.InvCode) {
                            showMsg = '当前产线无产品在生产中';
                            $.toptip(showMsg, "warning");
                            currSelf.SetOperateRecord(showMsg, false);
                            AudioUtils.Play(AudioUtils.ScanCodeFail);
                        } else if (currSelf.CurrProcessType != currSelf.FormData.InvProcessType) {
                            showMsg = '工序类型不匹配不能过站,请核对!';
                            $.toptip(showMsg, "warning");
                            currSelf.SetOperateRecord(showMsg, false);
                            AudioUtils.Play(AudioUtils.ScanCodeFail);
                        } else if (!barCode || barCode.length <= 0) {
                            showMsg = 'SN码不能为空';
                            $.toptip(showMsg, "warning");
                            currSelf.SetOperateRecord(showMsg, false);
                            AudioUtils.Play(AudioUtils.ScanCodeFail);
                        } else {
                            var IsCheckBarCode = CheckProductBarCode(currSelf.FormData.InvCode, barCode);//校验或换产
                            if (IsCheckBarCode.IsSuccess) {
                                currSelf.CurrBarCode = barCode;
                                currSelf.IsSubmit = false;
                                currSelf.FormData.InvBarCode = currSelf.CurrBarCode;
                                currSelf.SetOperateRecord(currSelf.CurrBarCode + ",扫码成功", true);
                                AudioUtils.Play(AudioUtils.ScanCodeSuccess);
                            } else {
                                AudioUtils.Play(AudioUtils.ScanCodeFail);
                                currSelf.SetOperateRecord(barCode + "," + IsCheckBarCode.message, false);
                                if (IsCheckBarCode.ErrorCode == 10199) {
                                    currSelf.SetBasetData(IsCheckBarCode.Data);
                                    currSelf.SetOperateRecord("生产线已经更换产品{" + currSelf.FormData.InvName + "},请重新扫码", false);
                                }
                            }
                        }
                        currSelf.IsDisable = false;
                    }
                },
                PassSubmitData: function (InvBarCode, async) {
                    var currSelf = this;
                    $.showLoading();
                    var InvBarCode = InvBarCode ? InvBarCode : currSelf.CurrBarCode;
                    currSelf.IsSubmit = true;
                    var jsonStr = JSON.stringify({ "BGSJ_TMH": InvBarCode, "BGSJ_CPBH": currSelf.FormData.InvCode, "BGSJ_SL": 1, "BGSJ_SCRWID": currSelf.FormData.ScheduleID, "BGSJ_PDJG_CODE": "PDJG01" });

                    var record = { BarCode: InvBarCode, InvName: currSelf.FormData.InvName, InvStd: currSelf.FormData.InvStd, StationTime: (new Date()).toLocaleTimeString(), Operator: LocalUserInfo.GetUserInfo().UserName, PassState: "Pass" };

                    $.ajax({
                        type: "post",
                        async: async ? false : true,
                        url: LocalConfig.SrvPath + "/jgmes/commonAction!doJsonSaveBGSJAll.action",
                        data: { "userCode": LocalUserInfo.GetUserInfo().UserCode, "mac": LocalUserInfo.GetUserInfo().Mac, "jsonStr": jsonStr },
                        dataType: "json",
                        success: function (ret) {
                            var retData = ReturnData(ret);
                            if (retData.IsSuccess) {
                                currSelf.ScanCodeNum++;
                                showMsg = InvBarCode + ",过站成功!";
                                $.toptip(showMsg, 'success');
                                AudioUtils.Play(AudioUtils.OutStationSuccess);
                                currSelf.SetOperateRecord(showMsg, true);
                            } else {
                                showMsg = InvBarCode + ",过站失败";
                                record.PassState = "过站失败";
                                AudioUtils.Play(AudioUtils.OutStationFail);
                                currSelf.SetOperateRecord(showMsg + ",失败原因:" + retData.message, false);
                            }
                            currSelf.StationRecord.splice(0, 0, record);
                        }, error: function (xhr, status, errorThrown) {
                             console.error(status);
                            $.alert("请求过程中发生异常");
                        }, complete: function () {
                            $.hideLoading();
                        }
                    });
                },
                SubmitData: function () {
                    var currSelf = this;
                    var showMsg;
                    if (!currSelf.SelectItemData || currSelf.SelectItemData.length == 0) {
                        showMsg = "请选择不良项目!";
                        $.toptip(showMsg, "warning");
                        currSelf.SetOperateRecord(showMsg, false);
                    }
                    else {
                        currSelf.IsSubmit = true;
                        $.showLoading();
                        var jsonStr = JSON.stringify({ "BGSJ_TMH": currSelf.FormData.InvBarCode, "BGSJ_CPBH": currSelf.FormData.InvCode, "BGSJ_SL": 1, "BGSJ_SCRWID": currSelf.FormData.ScheduleID, "BGSJ_PDJG_CODE": "PDJG02" });
                        var jsonStrDetail = [];

                        if (currSelf.SelectItemData && currSelf.SelectItemData.length > 0) {
                            for (var i in currSelf.SelectItemData) {
                                var element = currSelf.SelectItemData[i];
                                jsonStrDetail.push({ "BGSJZB_BLBH": element.ID, "BGSJZB_BLMC": element.ItemName });
                            }
                        }
                        var record = { BarCode: currSelf.FormData.InvBarCode, InvName: currSelf.FormData.InvName, InvStd: currSelf.FormData.InvStd, StationTime: (new Date()).toLocaleTimeString(), Operator: LocalUserInfo.GetUserInfo().UserName, PassState: "Pass" };

                        $.ajax({
                            type: "post",
                            url: LocalConfig.SrvPath + "/jgmes/commonAction!doJsonSaveBGSJAll.action",
                            data: { "userCode": LocalUserInfo.GetUserInfo().UserCode, "mac": LocalUserInfo.GetUserInfo().Mac, "jsonStr": jsonStr, "jsonStrDetail": JSON.stringify(jsonStrDetail) },
                            dataType: "json",
                            success: function (ret) {
                                var retData = ReturnData(ret);
                                if (retData.IsSuccess) {
                                    currSelf.ScanCodeNum++;
                                    showMsg = currSelf.FormData.InvBarCode + ",提交成功";
                                    $.toptip(showMsg, 'success');
                                    currSelf.SetOperateRecord(showMsg, true);
                                    AudioUtils.Play(AudioUtils.SubmitSuccess);
                                    //currSelf.SelectItemData = [];
                                    //currSelf.DefectiveItemData = [];
                                } else {
                                    showMsg = currSelf.FormData.InvBarCode + ",提交失败";
                                    AudioUtils.Play(AudioUtils.SubmitFail);
                                    record.PassState = "提交失败";
                                    $.toptip(showMsg, 'error');
                                    currSelf.SetOperateRecord(showMsg + retData.message, false);
                                }
                            }, error: function (xhr, status, errorThrown) {
                                 console.error(status);
                                $.alert("提交过程中发生异常");
                            }, complete: function () {
                                $.hideLoading();
                                $("#BarCode").focus();
                            }
                        });
                    }
                },
                SubmitDetectionItem: function (item) {
                    var currSelf = this;
                    if ($("#" + item.ID)[0].style.display == "none") {
                        $("#" + item.ID).show();
                        //检测提交数据
                        currSelf.SelectItemData.push(item);
                    } else {
                        for (var index in currSelf.SelectItemData) {
                            if (currSelf.SelectItemData[index].ID == item.ID) {
                                currSelf.SelectItemData.splice(index, 1);
                                $("#" + item.ID).hide();
                                return;
                            }
                        }
                    }
                }
            },
        });
    </script>
</body>

</html>